package cn.lyvust.work.exam04;

/**
 * Description:模拟接力赛跑
 * date: 2021-5-17 20:55
 *
 * @author Guo_guo
 * @since JDK 1.8
 */
public class RunThread implements Runnable {
    private int count;

    public void run() {
        while(count < 1000) {
            running();
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    public synchronized void running() {
        if (count >= 1000) {
            System.out.println("比赛结束");
            return;
        }
        System.out.println(Thread.currentThread().getName()+"拿到接力棒！");
        for (int j = 0; j <10; j++) {
            count+=10;
            try {
                Thread.sleep(200);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("跑"+count+"米的选手是---"+Thread.currentThread().getName());
        }
    }
}
